// 1.遍历键值对
var scores = ["Bob": 65, "Alice": 85, "Charlie": 95]
for (name, score) in scores {
    print("\(name)'s score is \(score)")
}

// 2.遍历字典的键
for name in scores.keys {
    print("Name: \(name)")
}

// 3.遍历字典的值
for score in scores.values {
    print("Score: \(score)")
}

// 4.排序遍历
// 按值排序字典
for (name, score) in scores.sorted(by: { $0.value > $1.value }) {
    print("\(name)'s score is \(score)")
}
// 按键排序字典
for (name, score) in scores.sorted(by: { $0.key < $1.key }) {
    print("\(name)'s score is \(score)")
}
